package com.ddstation.crm.common.controller;

import com.ddstation.common.district.entity.MaDistrictEntity;
import com.ddstation.common.district.service.DistrictService;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.inject.Inject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 省市县选择
 * @author zhangdifeng
 * @date 2018年11月22日
 */
@Controller @Lazy
public class DistrictController {

	@RequestMapping(value = {"/invs_district.do/load"})
	public @ResponseBody Map<String, Object> loadDistrictEvent(
			@RequestParam(required=false) Integer province
			,@RequestParam(required=false) Integer city) {
		Map<String, Object> retMap = new HashMap<String, Object>();
		retMap.put("errcode", "0");
		retMap.put("provinces", districtService.getProvince());
		if (province != null) {
			retMap.put("citys", districtService.getDistrict(province));
		}
		if (city != null) {
			List<MaDistrictEntity> countys = districtService.getDistrict(city);
			if (countys != null && !countys.isEmpty()) {
				retMap.put("countys", countys);	
			}
		}
		return retMap;
	}
	
	@Inject private DistrictService districtService = null;
}
